package com.feiyuan.modules.sys.controller;

import com.feiyuan.common.utils.ResponseUtils;
import com.feiyuan.modules.sys.entity.UserEntity;
import com.feiyuan.modules.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/login")
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/")
    public ResponseUtils login(@RequestBody UserEntity user) {
        Map<String, Object> map = new HashMap<>();
        map.put("userName", user.getUserName());
        map.put("password", user.getPassword());
        Object obj = userService.login(map);
        return new ResponseUtils().put("login", obj);
    }

    @GetMapping("/info")
    public ResponseUtils info(HttpServletRequest request) {
        return new ResponseUtils().put("result", userService.info(request));
    }

    /**
     * 退出
     * @return
     */
    @PostMapping("/logout")
    public ResponseUtils logout(HttpServletRequest request) {

        return new ResponseUtils();
    }
}
